package www.xudan.android_ffmpeg.videoplayer.sample;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


import java.util.List;

import www.xudan.android_ffmpeg.R;
import www.xudan.android_ffmpeg.videoplayer.model.VideoModel;

public class MyAdapter extends RecyclerView.Adapter<MyViewHolder> {
    Context context;
    List<VideoModel> list;

    public MyAdapter(Context context, List<VideoModel> list) {
        this.context = context;
        this.list = list;
    }


    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_vedio, viewGroup, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
        myViewHolder.playerView.releasePlayer();
        myViewHolder.playerView.getVideoPicImageView().setImageResource(R.drawable.pic);//设置首帧
        myViewHolder.playerView.setItemIndex(i);
        myViewHolder.playerView.setVideoModel(list.get(i));
        myViewHolder.playerView.setTitle("测试测试测试测试测试测试测试测试测试测试");
        myViewHolder.textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.startActivity(new Intent(context, Sample2Activity.class));
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
}
